# Topic 13 a Confidence intervals when sigma is known # find y such that P( -y < X < y ) = 0.95 qnorm( (1-0.95)/2, lower.tail=FALSE) # bring this back to a N( mu, 17.6/sqrt(32)) # first recompute but save the value y <- qnorm( (1-0.95)/2, lower.tail=FALSE) y -y*17.6/sqrt( 32 ) y*17.6/sqrt( 32 ) # we can do a few problems # find the 95% confidence interval for the mean of a # population with known standard deviation 3.67 based # on a sample of size 28 with sample mean = 76.9 # sigma <- 3.67 #population standard deviation n <- 28 # sample size x_bar <- 76.9 # sample mean alpha <- 0.95 # desired confidence level z <- qnorm( (1-alpha)/2, lower.tail = FALSE ) # z value for N(0,1) # get low and high sides of the confidence interval x_bar - z * sigma / sqrt( n ) # low side x_bar + z * sigma / sqrt( n ) # high side # find the 93% confidence interval for the mean of a # population with known standard deviation 8.06 based # on a sample of size 35 with sample mean = 1.27 # sigma <- 8.06 #population standard deviation n <- 35 # sample size x_bar <- 1.27 # sample mean alpha <- 0.93 # desired confidence level z <- qnorm( (1-alpha)/2, lower.tail = FALSE ) # z value for N(0,1) # get low and high sides of the confidence interval x_bar - z * sigma / sqrt( n ) # low side x_bar + z * sigma / sqrt( n ) # high side # find the 98.5% confidence interval for the mean of a # population with known standard deviation 15.4 based # on a sample of size 11 with sample mean = 26.7 # sigma <- 15.4 #population standard deviation n <- 11 # sample size x_bar <- 26.7 # sample mean alpha <- 0.985 # desired confidence level z <- qnorm( (1-alpha)/2, lower.tail = FALSE ) # z value for N(0,1) # get low and high sides of the confidence interval x_bar - z * sigma / sqrt( n ) # low side x_bar + z * sigma / sqrt( n ) # high side # # It is clear that we could do sample after sample in # this way. There are a few points to observe here, however, # Each time we do the pair of lines, 45 and 46, we # have R compute z * sigma / sqrt( n ) two times. # We will call this value the Margin of Error, or MOE. # Then we can compute it once. # # Find the 85% confidence interval for the mean of a # population with known standard deviation 6.97 based on # a sample of size 26 with sample mean = 437.2. z <- qnorm( 0.15/2, lower.tail=FALSE) MOE <- z*6.97/sqrt( 26 ) 437.2 - MOE # the low value 437.2 + MOE # the high value # do this again with our function source("../ci_known.R") ci_known( 6.97, 26, 437.2, 0.85 ) # for a population with known sigma=13.4, taking a sample # of size 15, getting a sample of sample mean=8.74 # look at changes for different levels of confidence ci_known( 13.4, 15, 8.74, 0.80 ) # 80% ci_known( 13.4, 15, 8.74, 0.90 ) # 90% ci_known( 13.4, 15, 8.74, 0.98 ) # 98% ci_known( 13.4, 15, 8.74, 0.999 ) # 99.9% # do the same thing but keep level at 0.90 and change # the sample size ci_known( 13.4, 25, 8.74, 0.90 ) # n=25 ci_known( 13.4, 45, 8.74, 0.90 ) # n=45 ci_known( 13.4, 85, 8.74, 0.90 ) # n=85